//
//  ZPasswordVC.m
//  WeClubs
//
//  Created by Zed Link on 5/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZPasswordVC.h"
#import "ZUserInfo.h"

@interface ZPasswordVC ()

@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UIButton *nextStepBtn;

@end

@implementation ZPasswordVC

+ (instancetype)zNew
{
    return [self zStoryboardInstanceWithStoryboardName:@"LoginAndRegister"];
}

- (void)zConfigNavigation
{
    [super zConfigNavigation];
    
    [self zAddBackItemWithGesture:YES];
    self.navigationItem.title = @"修改密码";
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:LOGIN_VIEW_BG_COLOR];
    
    // 输入密码才能下一步
    self.nextStepBtn.enabled = NO;
    [self.pwdField addTarget:self action:@selector(verifyCodeDidChange:) forControlEvents:UIControlEventEditingChanged];
}

- (void)verifyCodeDidChange:(UITextField *)textField
{
    if (textField == self.pwdField && textField.text.length > 0) {
        self.nextStepBtn.enabled = YES;
    } else {
        self.nextStepBtn.enabled = NO;
    }
}

#pragma mark - Control Action

- (IBAction)joinAction:(id)sender
{
    NSString *password = self.pwdField.text;
    #warning done

    NSDictionary *dataPara = @{
                               @"user_id" : @([ZUserInfo sharedInstance].userId),
                               @"token" : [ZUserInfo sharedInstance].token,
                               @"password" : [password zMD5HexString],
                               };
    
    [HTTPRequest POST:kChange_passwordUrl parameter:dataPara success:^(id resposeObject) {
           // 密码修改成功
    } failure:^(NSError *error) {
        
    }];
//    [[ZNetManager sharedInstance] changePassword:password success:^(ZNetManagerStatus status, NSString *resultMsg, NSDictionary *data) {
//        // 密码修改成功
//        
//    } failure:nil];
}

@end
